package com.sky.controller.user;


import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.UserOrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户订单接口")
@Slf4j
@RestController
@RequestMapping("/user/order")
public class UserOrderController {


    @Autowired
    private UserOrderService userOrderService;

    /**
     * 创建订单
     *
     * @return
     */
    @ApiOperation("创建订单")
    @PostMapping("/submit")
    public Result submitOrder(@RequestBody OrdersSubmitDTO dto) {

        OrderSubmitVO result = userOrderService.submitOrder(dto);
        return Result.success(result);
    }

    /**
     * 订单支付
     *
     * @return
     */
    @ApiOperation("支付")
    @PutMapping("/payment")
    public Result payment(@RequestBody OrdersPaymentDTO dto) {

        OrderPaymentVO result = userOrderService.payment(dto);
        return Result.success(result);
    }

    /**
     * 历史订单查询
     *
     * @param dto
     * @return
     */
    @ApiOperation("历史订单查询")
    @GetMapping("/historyOrders")
    public Result historyOrders(OrdersPageQueryDTO dto) {

        PageResult result = userOrderService.historyOrders(dto);

        return Result.success(result);
    }

    /**
     * 订单详情
     *
     * @return
     */
    @ApiOperation("订单详情")
    @GetMapping("/orderDetail/{id}")
    public Result orderDetail(@PathVariable Long id) {

        OrderVO orderVO = userOrderService.ordersDetail(id);

        return Result.success(orderVO);
    }

    /**
     * 再来一单
     * @return
     */
    @ApiOperation("再来一单")
    @PostMapping("/repetition/{id}")
    public Result repetition(@PathVariable Long id){

        userOrderService.repetition(id);

        return Result.success();
    }

    /**
     * 用户端取消订单
     * @param id
     * @return
     */
    @ApiOperation("用户端取消订单")
    @PutMapping("/cancel/{id}")
    public Result cancelOrder(@PathVariable Long id){

        userOrderService.cancelOrder(id);

        return Result.success();
    }

    /**
     * 用户催单
     * @param id
     * @return
     */
    @ApiOperation("用户催单")
    @GetMapping("/reminder/{id}")
    public Result remind(@PathVariable Long id){

        userOrderService.reminder(id);
        return Result.success();
    }

}
